﻿using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 纸片人.InterfaceFolder;
using 纸片人.Shaders;

namespace 纸片人.win2dEffectControl.DataClass
{
    public class DistortionEffectData : PixelShaderEffectData
    {
        #region 属性
        private float angle;
        private bool pronation;

        public float Angle { get => angle; set { angle = value; OnPropertyChanged();SetIsChanges(); } }

        public override ShaderType shaderShaderPath { get; } = ShaderType.Distortion;
        public bool Pronation { get => pronation; set { pronation = value; OnPropertyChanged(); SetIsChanges(); } }
        #endregion
        public override ICanvasImage GetEffect(CanvasDevice device, bool compression)
        {

            var source = GetSourceEffect(device, compression);
            if (source == null)
                return null;
            if (shaderCodeBytes == null)
                return null;

            var effect = new PixelShaderEffect(shaderCodeBytes);
            effect.Source1 = source;
           
            effect.SetFloat("angle", (float)(angle / 180 * Math.PI));
            effect.SetFloat2("size", new System.Numerics.Vector2((float)Size.Width, (float)Size.Height));
            effect.SetBoolean("pronation", Pronation);
            foreach (var item in effect.Properties)
            {
                var i = item;
            }
            return effect;
         
        }
    }
}
